🔒 fix: patch CodeQL XSS (#1) and path-injection (#2) alerts - #6
Merged
Conversation
… static server Resolves two CodeQL code-scanning alerts. js/xss (public/index.html): appendAuditEntry built the audit row via innerHTML, and the attacker-controlled `entry.source` was concatenated raw into a class attribute (`sourceClass`) with no escaping. A crafted `source` could break out of the attribute and inject markup. Rebuild the row with createElement + textContent so untrusted values can never be parsed as HTML, and restrict the source-derived CSS class to a safe token. js/path-injection (server.js): serveStatic relied on a startsWith guard over a path.join result, which does not decode %2e%2e or collapse encoded traversal. Decode the URL, strip the query, normalize, resolve against publicDir, and reject anything escaping the root. Verified: npm test 25/25; traversal probes (/../server.js, /%2e%2e/server.js, encoded variants) all 404 while normal assets serve; injected audit payload renders as inert text with no script execution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves the two open CodeQL code-scanning alerts. Independent of PRs #4/#5; branched from current
origin/main.Alert #2 —
js/path-injection(server.js:89) — FIXEDThe static handler guarded traversal with
!filePath.startsWith(publicDir)over apath.joinresult. That guard doesn't decode%2e%2eor collapse encoded traversal, so it's known-weak. Now the handler:new URL(...).pathname+decodeURIComponent)path.posix.normalizes the path, resolves it againstpublicDirwithpath.resolvepublicDirMalformed encoding returns 400.
Alert #1 —
js/xss(public/index.html:605) — FIXED (real, not a false positive)appendAuditEntrybuilt the row viainnerHTML. Most values passed throughesc(), but the attacker-controlledentry.sourcewas concatenated raw into aclassattribute:sourceoriginates from the unauthenticatedPOST /api/eventsbody, so a crafted value like"><img src=x onerror=...>breaks out of the attribute. (esc()istextContent→innerHTML, which doesn't escape quotes, so wrapping wouldn't have fully fixed the attribute context either.)Fix: rebuild the row with
createElement+textContent(noinnerHTML), and restrict the source-derived class to a safe token ([^a-zA-Z0-9_-]→-). Legitimate source classes (audit-source-agent-gateway,-agent-platform,-user) are unchanged, so styling is preserved.Verification
npm test→ 25/25 pass--path-as-is):/../server.js,/../../server.js,/%2e%2e/server.js,/..%2f..%2fserver.js,/../translate.js,/../../etc/passwd→ all 404, no source leaked. Normal assets (/,/index.html,/topology.js,/theme.css,/registry-panel.js,/./index.html) → 200.source='"><img src=x onerror=...>'and a<script>summary → no script executed, 0 injectedimg/script/belements, values rendered as inert text, legit class styling intact.No inline suppressions added; no existing behavior weakened.